//package com.zkthink.ceres.product.service.impl;
//
//import com.zkthink.base.R;
//import com.zkthink.base.service.SuperServiceImpl;
//import com.zkthink.ceres.product.dao.ProductImgMapper;
//import com.zkthink.ceres.product.dao.ProductMapper;
//import com.zkthink.ceres.product.entity.Product;
//import com.zkthink.ceres.product.entity.ProductImg;
//import com.zkthink.ceres.product.entity.MemberProductHistoryVO;
//import com.zkthink.ceres.product.entity.SimpleProductVO;
//import com.zkthink.ceres.server.entity.Store;
//import com.zkthink.ceres.server.service.StoreService;
//import com.zkthink.database.mybatis.conditions.Wraps;
//import com.zkthink.dozer.DozerUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Slf4j
//@Service
//public class ProductMemberHistoryServiceImpl extends SuperServiceImpl<ProductMemberHistoryMapper, ProductMemberHistory> implements ProductMemberHistoryService {
//
//    @Autowired
//    private DozerUtils dozerUtils;
//
//    @Autowired
//    private ProductMapper productMapper;
//
//    @Autowired
//    private ProductImgMapper productImgMapper;
//    @Autowired
//    private ProductServiceImpl productServiceImpl;
//    @Autowired
//    private StoreService storeService;
//
//    @Override
//    public R<MemberProductHistoryVO> findMemberProductHistoryList(MemberProductHistoryDTO f) {
//
//        Integer pageIndex = f.getCurrent();
//        Integer pageSize = f.getSize();
//        if (pageIndex == null || pageIndex < 1) {
//            pageIndex = 1;
//        }
//        if (pageSize == null || pageSize <= 0 || pageSize > 50) {
//            pageSize = 10;
//        }
//        int start = (pageIndex - 1) * pageSize;
//        int end = pageIndex * pageSize;
//        Integer count = baseMapper.selectCount(Wraps.<ProductMemberHistory>lbQ()
//                .eq(ProductMemberHistory::getMid, f.getMid()).eq(ProductMemberHistory::getIsDelete, 0)
//                .orderByDesc(ProductMemberHistory::getCreateTime)
//        );
//        List<ProductMemberHistory> productMemberHistoryList = baseMapper.selectList(Wraps.<ProductMemberHistory>lbQ()
//                .eq(ProductMemberHistory::getMid, f.getMid()).eq(ProductMemberHistory::getIsDelete, 0)
//                .orderByDesc(ProductMemberHistory::getCreateTime)
//                .last("limit " + start + "," + end)
//        );
//        List<Long> productId = new ArrayList<>();
//        List<Product> productList = new ArrayList<>();
//        for (ProductMemberHistory productMemberHistory : productMemberHistoryList) {
//            Product product = productMapper.selectById(productMemberHistory.getProductId());
//            productList.add(product);
//        }
//
//        List<SimpleProductVO> productVOList = dozerUtils.mapList(productList, SimpleProductVO.class);
//        for (SimpleProductVO productVO : productVOList) {
//            List<ProductImg> productImgs = productImgMapper.selectByProductId(productVO.getId());
//            List<String> imgs = new ArrayList<String>();
//            for (ProductImg productImg : productImgs) {
//                imgs.add(productImg.getImgPath());
//            }
//            productVO.setImgs(imgs);
//
//            //查询付款人数
//            Integer buyCount = productMapper.getProductBuyCount(productVO.getId());
//            productVO.setBuyCount(buyCount);
//
//            Store server = storeService.findByStroeId(productVO.getStoreId());
//            if (server != null) {
//                productVO.setTenantCode(storeService.findTenantCodeByStoreId(productVO.getStoreId()));
//                productVO.setStoreName(server.getStoreName());
//                productVO.setStoreLogo(server.getLogo());
//            }
//        }
//        MemberProductHistoryVO memberProductHistoryVO = new MemberProductHistoryVO();
//        memberProductHistoryVO.setTotal(count);
//        memberProductHistoryVO.setGoodsList(productVOList);
//        return R.success(memberProductHistoryVO);
//    }
//
//    @Override
//    public R DeleteMemberProductHistoryById(MemberProductHistoryDTO f) {
//        ProductMemberHistory productMemberHistory = new ProductMemberHistory();
//        productMemberHistory.setProductId(f.getId());
//        productMemberHistory.setIsDelete(1);
//        baseMapper.updateById(productMemberHistory);
//        return R.success();
//    }
//
//    @Override
//    public R DropMemberProductHistoryByMid(MemberProductHistoryDTO f) {
//        baseMapper.DropMemberProductHistoryByMid(f.getMid());
//        return R.success();
//    }
//
//}
